window.onload = function() {
    let username = document.getElementById("username")
    let password = document.getElementById("password")
    let name = username.value
    let pass = password.value
        // console.log(username.value)
        // let pos=document.getElementById("pos")
        // pos.checked=true
        // pos.addEventListener("change",()=>{
        //     console.log("复选框有变动")
        //     console.log(pos.checked)
        // })
        // username.addEventListener("input",(e)=>{
        //     console.log(e.target.value)
        // })
        // let city=document.querySelector("#city")
        // city.addEventListener("change",(e)=>{
        //     console.log(e.target.value)
        // })
        // let xhr = new XMLHttpRequest()
        //     //1.建立连接
        // xhr.open("GET", "http://172.19.11.61:8080/login" + "?username=" + name + "&password=" + pass, false)
        //     //2.异步请求的状态监听
        // xhr.onreadystatechange = function() {
        //     if (xhr.readyState === 4 && xhr.status === 200) {
        //         console.log("请求成功")
        //             //4.得到响应
        //         console.log(xhr.responseText)
        //     }
        // }
        // console.log("代码1")
        //     //3.发送请求
        // xhr.send()
        // console.log("代码2")
        // console.log("代码3")
    let button = document.getElementsByTagName("button")[0]
    button.addEventListener("click", () => {
        let promise = new Promise((resolve, reject) => {
            let xhr = new XMLHttpRequest()
                //1.建立连接
            xhr.open("GET", "http://172.19.14.60:8080/login" + "?username=" + name + "&password=" + pass, true)
                //2.异步请求的状态监听
            xhr.onreadystatechange = function() {
                if (xhr.readyState === 4 && xhr.status === 200) {
                    console.log("请求成功")
                    resolve(xhr.responseText)
                        //4.得到响应
                        // console.log()
                }
            }
            console.log("代码1")
                //3.发送请求
            xhr.send()
        })
        promise.then((res) => {
            console.log("success")
            console.log(res)
        }).catch(() => {
            console.log("err")
        }).finally(() => {
            console.log("both")
        })

    })

    setTimeout(() => {
        console.log("5")
    }, 5000)
}